<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery-3.7.1.min.js"></script>
</head>
<body>
    <button id="restart">重新开始一局游戏</button><br>
    <span>请输入要猜的数字:</span>
    <input type="text" name="" id="guessnum">
    <button id="guess">猜</button><br>
    <span>已经猜的次数:</span>
    <span id="count">0</span><br>
    <span>结果：</span>
    <span id="result"></span>
    <!-- // 生成数字 -->
    <script>
        let count=0;
        let num=Math.floor(Math.random()*100)+1;//向下取整
        console.log(num);
        $("#guess").click(function(){
            count++;
           let guessnum=$("#guessnum").val();
           $("#count").text(count);
           if(guessnum>num){
            $("#result").text("猜大啦");
            $("#result").css("color","red");
           }else if(guessnum<num){
            $("#result").text("猜小啦");
            $("#result").css("color","red");
           }else{
            $("#result").text("猜对啦");
            $("#result").css("color","green");
           }
        });
        $("#restart").click(function(){
            num=Math.floor(Math.random()*100)+1;
            console.log(num);
            count=0;
            $("#result").text("");
            $("#count").text(count);
            $("#guessnum").val("");
        });


    </script>

    
    
</body>
</html>